﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcCms.Core.Cache;

namespace MvcCms.Data.Service.Code
{
    /// <summary>
    /// Provides Account Data to Service Layer projects - Business Logic Should Not Be Placed Here Unless Data Specific such as limiting results returned.
    /// Don't do ToList here allow that to be done next layer up.
    /// </summary>
    public class AccountDataService : IAccountDataService
    {
        #region Constructors
        private readonly IAccountRepository _repository;
        private readonly ICacheService _cacheService;
        public AccountDataService(IAccountRepository repository, ICacheService cacheService)
        {
            _repository = repository;
            _cacheService = cacheService;
        }
        #endregion

        public IEnumerable<User> ListUsers()
        {
            var query = _repository.ListUsers().AsQueryable();
            var portalId = _cacheService.GetCurrentPortal().PortalID;
            query = query.Where(u => u.Portal.PortalID == portalId);

            return query;
        }
    }
}
